<?php

/*PERILAMVANONTAI OLES OI SUNARTISEIS POU EXOUN WS APOTELESMA TIN EMFANISI
DIAFORWN DEDOMENWN STIN SELIDA. PX TIN EPILOGI LOGIN I TO SUNOLO TWN MIXANWN STIN KATIGORIA BROWSE*/


	
/*
eksafanisi tou login kai tou register meta to login 
kai emfanisi tou meta to logout
*/
function show_login(){
		if(isset($_SESSION['log_status']))
		$login=$_SESSION['log_status'];
		if(!isset($_SESSION['log_status']))
		$login=FALSE;
		if($login!=TRUE) include("login.html");
	}

/*
emfanisi plaisiou me to onoma tou pelati
pou kanei login
kaleite sto common_header_navgator
*/
function client_recognition(){
		if(isset($_SESSION['last_name']))
		echo "<h3>Welcome Mr " . $_SESSION['last_name'] . "</h3>";
	}



/*
	otan kanei kapoios login emfanizete to logout alliws den emfanizete
	kaleite sto common_header_navgator
*/
function show_logout(){
	if(isset($_SESSION['log_status']))
	echo "<li><a href=" . "../html-php/logout.php" . ">Logout</a></li>";
}




/*
	to administrator panel emfanizete mono
	ean kanei login o administrator
	kaleite sto common_header_navgator
*/
function show_admin_panel()
{
		$admin_username='admin';
		$admin_password='12345';
	if(isset($_SESSION['username']) && isset($_SESSION['password']))
	{
		if($_SESSION['username']==$admin_username && $_SESSION['password']==$admin_password)
		{
			echo "<li><a href='admin_panel.php'>AdminPanel</a></li>";
		}
	}
}

/*
	emfanisi twn news gia oles tis katigories xristwn(guest user admin)
	kaleite sto home_container.php
	
*/
function show_news()
{
//emfanisi twn news gia toys guests
if(!isset($_SESSION['last_name']))
{
	$data=mysql_query("SELECT * FROM home_page_text WHERE name='news'") or die(mysql_error());
	while($info=mysql_fetch_array($data))
		{
			echo"<pre><p>" . $info['text'] . "</p></pre>";
		}
														
}
//emfanisi twn news gia tous users
if(isset($_SESSION['last_name']))
{
	if($_SESSION['last_name']!='administrator')
	{
		$data=mysql_query("SELECT * FROM home_page_text WHERE name='news'") or die(mysql_error());
		while($info=mysql_fetch_array($data))
			{
				echo"<pre><p>" . $info['text'] . "</p></pre>";
			}
	}
}
													
//emfanisi twn news gia ton administrator
if(isset($_SESSION['log_status']))
{
	if($_SESSION['last_name']=='administrator')
	{	
		if(isset($_POST['news']))
		{
			$news=$_POST['news'];
			mysql_query("UPDATE home_page_text SET text='$news' WHERE name='news'");
			$data=mysql_query("SELECT * FROM home_page_text WHERE name='news'") or die(mysql_error());
			while($info=mysql_fetch_array($data))
				{
					echo"<pre><p>" . $info['text'] . "</p></pre>";
				}
		}
		
		else
		{
			$data=mysql_query("SELECT * FROM home_page_text WHERE name='news'") or die(mysql_error());
			while($info=mysql_fetch_array($data))
			{
				echo"<pre><p>" . $info['text'] . "</p></pre>";
			}
		}
		
		}
	}	
}




/*emfanisi twn offers gia oles tis katigories xristwn(guest user admin)
kaleite sto home_container.php
*/
function show_offers()
{
//emfanisi twn offers gia toys guests
if(!isset($_SESSION['last_name']))
{
	$data=mysql_query("SELECT * FROM home_page_text WHERE name='offers'") or die(mysql_error());
	while($info=mysql_fetch_array($data))
		{
			echo"<pre><p>" . $info['text'] . "</p></pre>";
		}
														
}
//emfanisi twn offers gia tous users
if(isset($_SESSION['last_name']))
{
	if($_SESSION['last_name']!='administrator')
	{
		$data=mysql_query("SELECT * FROM home_page_text WHERE name='offers'") or die(mysql_error());
		while($info=mysql_fetch_array($data))
			{
				echo"<pre><p>" . $info['text'] . "</p></pre>";
			}
	}
}
													
//emfanisi twn offers gia ton administrator
if(isset($_SESSION['log_status']))
{
	if($_SESSION['last_name']=='administrator')
	{	
		if(isset($_POST['offers']))
		{
			$offers=$_POST['offers'];
			mysql_query("UPDATE home_page_text SET text='$offers' WHERE name='offers'");
			$data=mysql_query("SELECT * FROM home_page_text WHERE name='offers'") or die(mysql_error());
			while($info=mysql_fetch_array($data))
				{
					echo"<pre><p>" . $info['text'] . "</p></pre>";
				}
		}
		
		else
		{
			$data=mysql_query("SELECT * FROM home_page_text WHERE name='offers'") or die(mysql_error());
			while($info=mysql_fetch_array($data))
			{
				echo"<pre><p>" . $info['text'] . "</p></pre>";
			}
		}
		
		}
	}	
}




/*
emfanizei oles tis mixanes me ta xaraktiristika tous
kaleite stin selida browse_container.php
*/
function browse_all_models()
{
			$dir="http://localhost/bike_rental/pics/bikes/";
		$data=mysql_query("SELECT * FROM bike ORDER BY brand ASC");
		while($info=mysql_fetch_array($data))
		{
			$brand=$info['brand'];
			$model=$info['model'];
			$color=$info['color'];
			$year_of_make=$info['year_of_make'];
			$description=$info['description'];
			$photo_path=$info['photo_path'];
			$price=$info['price_per_day'];
			//emfanisi olwn twn montelwn
			$complete_path=$dir.$photo_path;
			
			echo" <div class='individual'>
    			  <img src='$complete_path'>
        				<div class='bike_details'>
        					<ul>
								<li>$brand</li>
								<li>$model</li>
								<li>$color</li>
								<li>$year_of_make</li>
								<li>$description</li>
								<li>Daily Price: $price Euro</li>
							</ul>
						</div>
					</div>";
		}
}



/*
	emfanizei oles tis markes gia epilogi kai anazitisi mixanis
	kaleite stin selida search_container.php
*/

function select_brand()
{
 $data=mysql_query("SELECT * FROM brands ORDER BY brand ASC");
			while($info=mysql_fetch_array($data))
			{
				$brand=$info['brand'];
				echo "<option value='$brand'>$brand</option>";
			}	
}



/*
	emfanisi tou periexomenou tou about us apo tin vasi deomenwn
	opws to exei orisei o administrator
	kaleite stin selida about_us_container
*/

function show_about_us()
{
//emfanisi twn news gia toys guests
if(!isset($_SESSION['last_name']))
{
	$data=mysql_query("SELECT * FROM contact_about_us WHERE name='about_us'") or die(mysql_error());
	while($info=mysql_fetch_array($data))
		{
			echo"<pre><p>" . $info['text'] . "</p></pre>";
		}
														
}
//emfanisi twn news gia tous users
if(isset($_SESSION['last_name']))
{
	if($_SESSION['last_name']!='administrator')
	{
		$data=mysql_query("SELECT * FROM contact_about_us WHERE name='about_us'") or die(mysql_error());
		while($info=mysql_fetch_array($data))
			{
				echo"<pre><p>" . $info['text'] . "</p></pre>";
			}
	}
}
													
//emfanisi twn news gia ton administrator
if(isset($_SESSION['log_status']))
{
	if($_SESSION['last_name']=='administrator')
	{	
		if(isset($_POST['about_us']))
		{
			$about_us=$_POST['about_us'];
			mysql_query("UPDATE contact_about_us SET text='$about_us' WHERE name='about_us'");
			$data=mysql_query("SELECT * FROM contact_about_us WHERE name='about_us'") or die(mysql_error());
			while($info=mysql_fetch_array($data))
				{
					echo"<pre><p>" . $info['text'] . "</p></pre>";
				}
		}
		
		else
		{
			$data=mysql_query("SELECT * FROM contact_about_us WHERE name='about_us'") or die(mysql_error());
			while($info=mysql_fetch_array($data))
			{
				echo"<pre><p>" . $info['text'] . "</p></pre>";
			}
		}
		
		}
	}	
	
}


/*
	emfanisi tou periexomenou tou contact us apo tin vasi deomenwn
	opws to exei orisei o administrator
	kaleite stin selida contact_us_container
*/
function show_contact_us()
{
//emfanisi twn news gia toys guests
if(!isset($_SESSION['last_name']))
{
	$data=mysql_query("SELECT * FROM contact_about_us WHERE name='contact_us'") or die(mysql_error());
	while($info=mysql_fetch_array($data))
		{
			echo"<pre><p>" . $info['text'] . "</p></pre>";
		}
														
}
//emfanisi twn news gia tous users
if(isset($_SESSION['last_name']))
{
	if($_SESSION['last_name']!='administrator')
	{
		$data=mysql_query("SELECT * FROM contact_about_us WHERE name='contact_us'") or die(mysql_error());
		while($info=mysql_fetch_array($data))
			{
				echo"<pre><p>" . $info['text'] . "</p></pre>";
			}
	}
}
													
//emfanisi twn news gia ton administrator
if(isset($_SESSION['log_status']))
{
	if($_SESSION['last_name']=='administrator')
	{	
		if(isset($_POST['contact_us']))
		{
			$contact_us=$_POST['contact_us'];
			mysql_query("UPDATE contact_about_us SET text='$contact_us' WHERE name='contact_us'");
			$data=mysql_query("SELECT * FROM contact_about_us WHERE name='contact_us'") or die(mysql_error());
			while($info=mysql_fetch_array($data))
				{
					echo"<pre><p>" . $info['text'] . "</p></pre>";
				}
		}
		
		else
		{
			$data=mysql_query("SELECT * FROM contact_about_us WHERE name='contact_us'") or die(mysql_error());
			while($info=mysql_fetch_array($data))
			{
				echo"<pre><p>" . $info['text'] . "</p></pre>";
			}
		}
		
		}
	}		
}



/*
	emfanisi olwn twn paraggeleiwn enos pelati
	ektos kai an exei diagrafei apo tin vasi dedomenwn
	kaleite stin selida browse_container.php
*/
function show_history()
{
		if(isset($_SESSION['username']))
		{
			echo"<h2>Order History</h2>";
			$username=$_SESSION['username'];
			$data=mysql_query("SELECT * FROM orders WHERE username='$username'") or die(mysql_error());
			while($info=mysql_fetch_array($data))
			{
				$id=$info['id'];
				$username=$info['username'];
				$bike_id=$info['bike_id'];
				$date_from=$info['date_from'];
				$date_to=$info['date_to'];
				$total_price=$info['total_price'];
			echo"<div class='orders'>
						Order Number:$id<br>
						Username:$username<br>
						Bike id:$bike_id<br>
						Date From:$date_from<br>
						Date To:$date_to<br>
						Total Price(Euros):$total_price<br>
				 </div>";			
			}	
		}	
}
								   				
?>



